package demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-03-28
 * Time: 11:07
 */
abstract class Animal {
    private String name;
    private int age;

    public abstract void eat();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

interface IFlying { void fly();}
interface IRunning { void run();}
interface ISwimming { void swim();}

class Cat extends Animal implements IRunning {
    public Cat(String name, int age) {
        super(name,age);
    }
    @Override
    public void run() {
        System.out.println(this.getName() + "正在用四条腿跑");
    }

    @Override
    public void eat() {
        System.out.println(this.getName() + "正在吃饭");
    }
}

class Fish extends Animal implements ISwimming {
    public Fish(String name, int age) {
        super(name,age);
    }
    @Override
    public void swim() {
        System.out.println(this.getName() + "正在用尾巴游泳");
    }
    @Override
    public void eat() {
        System.out.println(this.getName() + "正在吃饭");
    }
}

class Frog extends Animal implements IRunning, ISwimming {
    public Frog(String name, int age) {
        super(name,age);
    }
    @Override
    public void run() {
        System.out.println(this.getName() + "正在往前跳");
    }
    @Override
    public void swim() {
        System.out.println(this.getName() + "正在蹬腿游泳");
    }
    @Override
    public void eat() {
        System.out.println(this.getName() + "正在吃饭");
    }
}

class Duck extends Animal implements IRunning, ISwimming, IFlying {
    public Duck(String name, int age) {
        super(name, age);
    }
    @Override
    public void fly() {
        System.out.println(this.getName() + "正在用翅膀飞");
    }
    @Override
    public void run() {
        System.out.println(this.getName() + "正在用两条腿跑");
    }
    @Override
    public void swim() {
        System.out.println(this.getName() + "正在漂在水上");
    }
    @Override
    public void eat() {
        System.out.println(this.getName() + "正在吃饭");
    }
}
public class Test {

    public static void test1(Animal animal){
        animal.eat();
    }
    public static void testFly(IFlying iFlying){
        iFlying.fly();
    }

    public static void testRun(IRunning iRunning){
        iRunning.run();
    }

    public static void testSwim(ISwimming iSwimming){
        iSwimming.swim();
    }


    public static void main(String[] args) {
        test1(new Duck("青蛙",3));
        System.out.println("=======以上继承======");
        testFly(new Duck("小鸭",2));
        testRun(new Duck("小鸭",2));
        testSwim(new Duck("小鸭",2));
        System.out.println("========接口=========");
        testRun(new Frog("小蛙",1));
        testSwim(new Frog("小蛙",1));
        System.out.println("========接口=========");
        testSwim(new Fish("鱼",1));
    }
}
